package com.joekai.view_demo.foldList;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.joekai.view_demo.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @author joekai
 */
public class FoldListActivity extends AppCompatActivity {
    private List<String> mItems;
    private static final int LIST_NUM = 200;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fold_list);

        setTitle("汽车之家折叠列表");

        ListView mListView = findViewById(R.id.lv_);

        mItems = new ArrayList<>();
        for (int i = 0; i < LIST_NUM; i++) {
            mItems.add("i -> " + i);
        }
        mListView.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return mItems.size();
            }

            @Override
            public Object getItem(int position) {
                return null;
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                @SuppressLint("ViewHolder") View view = LayoutInflater.from(FoldListActivity.this).inflate(R.layout.adapter_main_item, parent, false);
                TextView fruitName = view.findViewById(R.id.txv_);
                fruitName.setText(mItems.get(position));
                return view;
            }
        });
    }
}